﻿@page "/docs/extensions/fluent-validation"

<Seo Canonical="/docs/extensions/fluent-validation" Title="Blazorise FluentValidation component" Description="Learn to use and work with the Blazorise FluentValidation component, which is used for building strongly-typed validation rules." />

<DocsPageTitle Path="Extensions/FluentValidation">
    Blazorise FluentValidation component
</DocsPageTitle>

<DocsPageLead>
    A validation component for building strongly-typed validation rules.
</DocsPageLead>

<DocsPageParagraph>
    This extension component is based on <Anchor To="https://github.com/FluentValidation/FluentValidation" Title="Link to FluentValidation">FluentValidation</Anchor>, a validation library for .NET that uses a fluent interface and lambda expressions for building strongly-typed validation rules.
</DocsPageParagraph>

<DocsPageSubtitle>
    Installation
</DocsPageSubtitle>

<DocsPageSection>
    <DocsPageSectionHeader Title="1. NuGet">
        Install extension from NuGet.
    </DocsPageSectionHeader>
    <DocsPageSectionSource Code="FluentValidationNugetInstallExample" />
</DocsPageSection>

<DocsPageSection>
    <DocsPageSectionHeader Title="2. Imports">
        In your main <Badge Color="Color.Light">_Imports.razor</Badge> add:
    </DocsPageSectionHeader>
    <DocsPageSectionSource Code="FluentValidationImportExample" />
</DocsPageSection>

<DocsPageSection>
    <DocsPageSectionHeader Title="3. Register Blazorise Services">
        Add the following lines to the relevant sections of <Badge Color="Color.Light">Program.cs</Badge>.
    </DocsPageSectionHeader>
    <DocsPageSectionSource Code="FluentValidationRegisterValidatorsExample" />
</DocsPageSection>

<DocsPageSubtitle>
    Examples
</DocsPageSubtitle>

<DocsPageSection>
    <DocsPageSectionHeader Title="Basic">
        <Paragraph>
            The process of validating the model is similar to our data annotation on our <Anchor To="docs/components/validation" Title="Link to Validation component">Validation component</Anchor>. First, as usual, we define the <Code>Model</Code> parameter. After which, we need to determine the <Code>HandlerType</Code>. To make it easier, we have allowed the definition of <Code>HandlerType</Code> on the <Code Tag>Validations</Code> level.
        </Paragraph>
        <Paragraph>
            By defining the handler type on a <Code Tag>Validations</Code> level, it will be shared and used by all the <Code Tag>Validation</Code> components inside it. Thus, no need to specify the handler type on each <Code Tag>Validation</Code> component.
        </Paragraph>
    </DocsPageSectionHeader>
    <DocsPageSectionContent Outlined FullWidth>
        <BasicFluentValidationExample />
    </DocsPageSectionContent>
    <DocsPageSectionSource Code="BasicFluentValidationExample" />
    <DocsPageSectionContent>
        Don't forget to create the <Strong>AbstractValidator</Strong> for your <Strong>Model</Strong>.
    </DocsPageSectionContent>
    <DocsPageSectionSource Code="FluentValidationAbstractValidatorExample" />
</DocsPageSection>